package cn.internship.modules.manage.service.impl;

import cn.internship.modules.manage.entity.ClassInfoEntity;
import cn.internship.modules.manage.entity.dto.MajorSearch;
import cn.internship.modules.manage.entity.vo.ClassInfoList;
import cn.internship.modules.manage.entity.vo.MajorList;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Service;
import java.util.Map;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import cn.internship.common.utils.PageUtils;
import cn.internship.common.utils.Query;

import cn.internship.modules.manage.dao.MajorInfoDao;
import cn.internship.modules.manage.entity.MajorInfoEntity;
import cn.internship.modules.manage.service.MajorInfoService;


@Service("majorInfoService")
public class MajorInfoServiceImpl extends ServiceImpl<MajorInfoDao, MajorInfoEntity> implements MajorInfoService {

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        IPage<MajorInfoEntity> page = this.page(
                new Query<MajorInfoEntity>().getPage(params),
                new QueryWrapper<MajorInfoEntity>()
        );

        return new PageUtils(page);
    }

    @Override
    public PageUtils listByPage(MajorSearch search) {
        LambdaQueryWrapper<MajorInfoEntity> userLambdaQueryWrapper = Wrappers.lambdaQuery();
        userLambdaQueryWrapper.like(StringUtils.isNotEmpty(search.getMajorNo()),MajorInfoEntity::getMajorNo,search.getMajorNo());

        Page<MajorInfoEntity> pageInfo = new Page<>(search.getPage() , search.getLimit());
        IPage<MajorList> page =this.baseMapper.queryList(pageInfo,userLambdaQueryWrapper);
        return new PageUtils(page);
    }

}